﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using App.Utilities.Web.Handlers;
using System.Data;
using CRMBiz;
using Newtonsoft.Json;
using CRMWeb.Utilities.Context;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for VerificationChecklistApplicant
    /// </summary>
    public class VerificationChecklistApplicant : BaseHandler
    {
        public override void OnMethodInvoke(OnMethodInvokeArgs e)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
            context.Response.Cache.SetExpires(DateTime.MinValue);
            context.Response.Cache.SetNoStore();

            //e.Cancel = true;

            SetResponseContentType(ResponseContentTypes.HTML);
        }

        public override void AfterMethodInvoke(object checklist)
        {
            base.AfterMethodInvoke(checklist);
        }

       
        public void UpdateVerificationChecklist(int totalApplicant, string app_id, string ApplicationContactID, string ApplicationContactID1, string ApplicationContactID2, string Income_Payslip, string Bank_LatestMonth, string Bank_FullName, string Bank_ACBSB, string Assert_Vehicles, string Assert_CouncilRate, string Assert_Mortage, string Assert_Valuation, string IDs_Residential_Rental, string Residential_Rate, string Boarding, string Bills, string IDs_PhotoID, string IDs_Card, string ExtraItemNo11, string ExtraItemNo21, string ExtraItemNo31, string ExtraItemNo41, string ExtraItemNo51, string ExtraItemNo61, string ExtraItemNo71, string ExtraItemNo81, string ExtraItemNo91, string ExtraItemNo101,
            string Income_Payslip1, string Bank_LatestMonth1, string Bank_FullName1, string Bank_ACBSB1, string Assert_Vehicles1, string Assert_CouncilRate1, string Assert_Mortage1, string Assert_Valuation1, string IDs_Residential_Rental1, string Residential_Rate1, string Boarding1, string Bills1, string IDs_PhotoID1, string IDs_Card1, string ExtraItemNo12, string ExtraItemNo22, string ExtraItemNo32, string ExtraItemNo42, string ExtraItemNo52, string ExtraItemNo62, string ExtraItemNo72, string ExtraItemNo82, string ExtraItemNo92, string ExtraItemNo102,
            string Income_Payslip2, string Bank_LatestMonth2, string Bank_FullName2, string Bank_ACBSB2, string Assert_Vehicles2, string Assert_CouncilRate2, string Assert_Mortage2, string Assert_Valuation2, string IDs_Residential_Rental2, string Residential_Rate2, string Boarding2, string Bills2, string IDs_PhotoID2, string IDs_Card2, string ExtraItemNo13, string ExtraItemNo23, string ExtraItemNo33, string ExtraItemNo43, string ExtraItemNo53, string ExtraItemNo63, string ExtraItemNo73, string ExtraItemNo83, string ExtraItemNo93, string ExtraItemNo103,
            string username)
        {
            try
            {

                int intapp_id = string.IsNullOrEmpty(app_id) ? 0 : int.Parse(app_id);

                int intIncome_Payslip = bool.Parse(Income_Payslip) ? 1 : 0;
                int intIncome_Payslip1 = bool.Parse(Income_Payslip1) ? 1 : 0;
                int intIncome_Payslip2 = bool.Parse(Income_Payslip2) ? 1 : 0;

                int intBank_LatestMonth = bool.Parse(Bank_LatestMonth) ? 1 : 0;
                int intBank_LatestMonth1 = bool.Parse(Bank_LatestMonth1) ? 1 : 0;
                int intBank_LatestMonth2 = bool.Parse(Bank_LatestMonth2) ? 1 : 0;

                int intBank_FullName = bool.Parse(Bank_FullName) ? 1 : 0;
                int intBank_FullName1 = bool.Parse(Bank_FullName1) ? 1 : 0;
                int intBank_FullName2 = bool.Parse(Bank_FullName2) ? 1 : 0;

                int intBank_ACBSB = bool.Parse(Bank_ACBSB) ? 1 : 0;
                int intBank_ACBSB1 = bool.Parse(Bank_ACBSB1) ? 1 : 0;
                int intBank_ACBSB2 = bool.Parse(Bank_ACBSB2) ? 1 : 0;

                int intAssert_Vehicles = bool.Parse(Assert_Vehicles) ? 1 : 0;
                int intAssert_Vehicles1 = bool.Parse(Assert_Vehicles1) ? 1 : 0;
                int intAssert_Vehicles2 = bool.Parse(Assert_Vehicles2) ? 1 : 0;

                int intAssert_CouncilRate = bool.Parse(Assert_CouncilRate) ? 1 : 0;
                int intAssert_CouncilRate1 = bool.Parse(Assert_CouncilRate1) ? 1 : 0;
                int intAssert_CouncilRate2 = bool.Parse(Assert_CouncilRate2) ? 1 : 0;

                int intAssert_Mortage = bool.Parse(Assert_Mortage) ? 1 : 0;
                int intAssert_Mortage1 = bool.Parse(Assert_Mortage1) ? 1 : 0;
                int intAssert_Mortage2 = bool.Parse(Assert_Mortage2) ? 1 : 0;

                int intAssert_Valuation = bool.Parse(Assert_Valuation) ? 1 : 0;
                int intAssert_Valuation1 = bool.Parse(Assert_Valuation1) ? 1 : 0;
                int intAssert_Valuation2 = bool.Parse(Assert_Valuation2) ? 1 : 0;

                int intIDs_Residential_Rental = bool.Parse(IDs_Residential_Rental) ? 1 : 0;
                int intIDs_Residential_Rental1 = bool.Parse(IDs_Residential_Rental1) ? 1 : 0;
                int intIDs_Residential_Rental2 = bool.Parse(IDs_Residential_Rental2) ? 1 : 0;

                int intResidential_Rate = bool.Parse(Residential_Rate) ? 1 : 0;
                int intResidential_Rate1 = bool.Parse(Residential_Rate1) ? 1 : 0;
                int intResidential_Rate2 = bool.Parse(Residential_Rate2) ? 1 : 0;

                int intBoarding = bool.Parse(Boarding) ? 1 : 0;
                int intBoarding1 = bool.Parse(Boarding1) ? 1 : 0;
                int intBoarding2 = bool.Parse(Boarding2) ? 1 : 0;

                int intBills = bool.Parse(Bills) ? 1 : 0;
                int intBills1 = bool.Parse(Bills1) ? 1 : 0;
                int intBills2 = bool.Parse(Bills2) ? 1 : 0;

                int intIDs_PhotoID = bool.Parse(IDs_PhotoID) ? 1 : 0;
                int intIDs_PhotoID1 = bool.Parse(IDs_PhotoID1) ? 1 : 0;
                int intIDs_PhotoID2 = bool.Parse(IDs_PhotoID2) ? 1 : 0;

                int intIDs_Card = bool.Parse(IDs_Card) ? 1 : 0;
                int intIDs_Card1 = bool.Parse(IDs_Card1) ? 1 : 0;
                int intIDs_Card2 = bool.Parse(IDs_Card2) ? 1 : 0;


                int intExtraItemNo11 = string.IsNullOrEmpty(ExtraItemNo11) ? 0 : int.Parse(ExtraItemNo11);
                int intExtraItemNo12 = string.IsNullOrEmpty(ExtraItemNo12) ? 0 : int.Parse(ExtraItemNo12);
                int intExtraItemNo13 = string.IsNullOrEmpty(ExtraItemNo13) ? 0 : int.Parse(ExtraItemNo13);

                int intExtraItemNo21 = string.IsNullOrEmpty(ExtraItemNo21) ? 0 : int.Parse(ExtraItemNo21);
                int intExtraItemNo22 = string.IsNullOrEmpty(ExtraItemNo22) ? 0 : int.Parse(ExtraItemNo22);
                int intExtraItemNo23 = string.IsNullOrEmpty(ExtraItemNo23) ? 0 : int.Parse(ExtraItemNo23);

                int intExtraItemNo31 = string.IsNullOrEmpty(ExtraItemNo31) ? 0 : int.Parse(ExtraItemNo31);
                int intExtraItemNo32 = string.IsNullOrEmpty(ExtraItemNo32) ? 0 : int.Parse(ExtraItemNo32);
                int intExtraItemNo33 = string.IsNullOrEmpty(ExtraItemNo33) ? 0 : int.Parse(ExtraItemNo33);

                int intExtraItemNo41 = string.IsNullOrEmpty(ExtraItemNo41) ? 0 : int.Parse(ExtraItemNo41);
                int intExtraItemNo42 = string.IsNullOrEmpty(ExtraItemNo42) ? 0 : int.Parse(ExtraItemNo42);
                int intExtraItemNo43 = string.IsNullOrEmpty(ExtraItemNo43) ? 0 : int.Parse(ExtraItemNo43);

                int intExtraItemNo51 = string.IsNullOrEmpty(ExtraItemNo51) ? 0 : int.Parse(ExtraItemNo51);
                int intExtraItemNo52 = string.IsNullOrEmpty(ExtraItemNo52) ? 0 : int.Parse(ExtraItemNo52);
                int intExtraItemNo53 = string.IsNullOrEmpty(ExtraItemNo53) ? 0 : int.Parse(ExtraItemNo53);

                int intExtraItemNo61 = string.IsNullOrEmpty(ExtraItemNo61) ? 0 : int.Parse(ExtraItemNo61);
                int intExtraItemNo62 = string.IsNullOrEmpty(ExtraItemNo62) ? 0 : int.Parse(ExtraItemNo62);
                int intExtraItemNo63 = string.IsNullOrEmpty(ExtraItemNo63) ? 0 : int.Parse(ExtraItemNo63);

                int intExtraItemNo71 = string.IsNullOrEmpty(ExtraItemNo71) ? 0 : int.Parse(ExtraItemNo71);
                int intExtraItemNo72 = string.IsNullOrEmpty(ExtraItemNo72) ? 0 : int.Parse(ExtraItemNo72);
                int intExtraItemNo73 = string.IsNullOrEmpty(ExtraItemNo73) ? 0 : int.Parse(ExtraItemNo73);

                int intExtraItemNo81 = string.IsNullOrEmpty(ExtraItemNo81) ? 0 : int.Parse(ExtraItemNo81);
                int intExtraItemNo82 = string.IsNullOrEmpty(ExtraItemNo82) ? 0 : int.Parse(ExtraItemNo82);
                int intExtraItemNo83 = string.IsNullOrEmpty(ExtraItemNo83) ? 0 : int.Parse(ExtraItemNo83);

                int intExtraItemNo91 = string.IsNullOrEmpty(ExtraItemNo91) ? 0 : int.Parse(ExtraItemNo91);
                int intExtraItemNo92 = string.IsNullOrEmpty(ExtraItemNo92) ? 0 : int.Parse(ExtraItemNo92);
                int intExtraItemNo93 = string.IsNullOrEmpty(ExtraItemNo93) ? 0 : int.Parse(ExtraItemNo93);

                int intExtraItemNo101 = string.IsNullOrEmpty(ExtraItemNo101) ? 0 : int.Parse(ExtraItemNo101);
                int intExtraItemNo102 = string.IsNullOrEmpty(ExtraItemNo102) ? 0 : int.Parse(ExtraItemNo102);
                int intExtraItemNo103 = string.IsNullOrEmpty(ExtraItemNo103) ? 0 : int.Parse(ExtraItemNo103);
                //First Check ApplicationContactId which comes is exist in applicationcontact table if yes then only insert/update record.
                // int IsExistApplicationContactID = VerificationChecklistHandler.IsExistApplicationContactID(intapp_id);

                if (totalApplicant == 1)
                {
                    VerificationChecklistHandler.EditVerificationChecklist(int.Parse(ApplicationContactID), intapp_id, intIncome_Payslip, intBank_LatestMonth, intBank_FullName, intBank_ACBSB, intAssert_Vehicles, intAssert_CouncilRate, intAssert_Mortage, intAssert_Valuation, intIDs_Residential_Rental, intResidential_Rate, intBoarding, intBills, intIDs_PhotoID, intIDs_Card, intExtraItemNo11, intExtraItemNo21, intExtraItemNo31, intExtraItemNo41, intExtraItemNo51, intExtraItemNo61, intExtraItemNo71, intExtraItemNo81, intExtraItemNo91, intExtraItemNo101, username);

                }
                else if (totalApplicant == 2)
                {
                    VerificationChecklistHandler.EditVerificationChecklist(int.Parse(ApplicationContactID), intapp_id, intIncome_Payslip, intBank_LatestMonth, intBank_FullName, intBank_ACBSB, intAssert_Vehicles, intAssert_CouncilRate, intAssert_Mortage, intAssert_Valuation, intIDs_Residential_Rental, intResidential_Rate, intBoarding, intBills, intIDs_PhotoID, intIDs_Card, intExtraItemNo11, intExtraItemNo21, intExtraItemNo31, intExtraItemNo41, intExtraItemNo51, intExtraItemNo61, intExtraItemNo71, intExtraItemNo81, intExtraItemNo91, intExtraItemNo101, username);
                    VerificationChecklistHandler.EditVerificationChecklist(int.Parse(ApplicationContactID1), intapp_id, intIncome_Payslip1, intBank_LatestMonth1, intBank_FullName1, intBank_ACBSB1, intAssert_Vehicles1, intAssert_CouncilRate1, intAssert_Mortage1, intAssert_Valuation1, intIDs_Residential_Rental1, intResidential_Rate1, intBoarding1, intBills1, intIDs_PhotoID1, intIDs_Card1, intExtraItemNo12, intExtraItemNo22, intExtraItemNo32, intExtraItemNo42, intExtraItemNo52, intExtraItemNo62, intExtraItemNo72, intExtraItemNo82, intExtraItemNo92, intExtraItemNo102, username);
                }
                else if (totalApplicant == 3)
                {
                    VerificationChecklistHandler.EditVerificationChecklist(int.Parse(ApplicationContactID), intapp_id, intIncome_Payslip, intBank_LatestMonth, intBank_FullName, intBank_ACBSB, intAssert_Vehicles, intAssert_CouncilRate, intAssert_Mortage, intAssert_Valuation, intIDs_Residential_Rental, intResidential_Rate, intBoarding, intBills, intIDs_PhotoID, intIDs_Card, intExtraItemNo11, intExtraItemNo21, intExtraItemNo31, intExtraItemNo41, intExtraItemNo51, intExtraItemNo61, intExtraItemNo71, intExtraItemNo81, intExtraItemNo91, intExtraItemNo101, username);
                    VerificationChecklistHandler.EditVerificationChecklist(int.Parse(ApplicationContactID1), intapp_id, intIncome_Payslip1, intBank_LatestMonth1, intBank_FullName1, intBank_ACBSB1, intAssert_Vehicles1, intAssert_CouncilRate1, intAssert_Mortage1, intAssert_Valuation1, intIDs_Residential_Rental1, intResidential_Rate1, intBoarding1, intBills1, intIDs_PhotoID1, intIDs_Card1, intExtraItemNo12, intExtraItemNo22, intExtraItemNo32, intExtraItemNo42, intExtraItemNo52, intExtraItemNo62, intExtraItemNo72, intExtraItemNo82, intExtraItemNo92, intExtraItemNo102, username);
                    VerificationChecklistHandler.EditVerificationChecklist(int.Parse(ApplicationContactID2), intapp_id, intIncome_Payslip2, intBank_LatestMonth2, intBank_FullName2, intBank_ACBSB2, intAssert_Vehicles2, intAssert_CouncilRate2, intAssert_Mortage2, intAssert_Valuation2, intIDs_Residential_Rental2, intResidential_Rate2, intBoarding2, intBills2, intIDs_PhotoID2, intIDs_Card2, intExtraItemNo13, intExtraItemNo23, intExtraItemNo33, intExtraItemNo43, intExtraItemNo53, intExtraItemNo63, intExtraItemNo73, intExtraItemNo83, intExtraItemNo93, intExtraItemNo103, username);
                }
                context.Response.Write(totalApplicant);
            }
            catch (Exception ex)
            {
                context.Response.Write("0");
                ErrorHandler.saveErrorLog(ex, CMSContext.CurrentUser.MemberName);
            }
        }
    }
}